#ifndef lock_server_cache_h
#define lock_server_cache_h

#include <string>
#include "lock_protocol.h"
#include "lock_client.h"
#include "rpc.h"
#include "lock_server.h"
#include <map>
#include <queue> 

#define LOCKED 1
#define FREE 0

typedef struct {
  int status;
  std::string curr;
}lock_info;

class lock_server_cache {
 public:
  std::map<lock_protocol::lockid_t, std::list<std::string> > lock_wanters;
  std::map<std::string, rpcc*> addr_book;
  std::map<lock_protocol::lockid_t, lock_info> lock_map;
  pthread_mutex_t lock_map_mutex;
  pthread_cond_t lock_map_cond_mutex;
  void print_lock_info (lock_info l, lock_protocol::lockid_t lid);
  lock_info make_new_lock_info();
  lock_info make_new_lock_info(std::string id);
  lock_server_cache();
  lock_protocol::status stat(lock_protocol::lockid_t, int &);
  void revoker();
  void retryer();
  lock_protocol::status acquire(lock_protocol::lockid_t lid, std::string rpc_id, int&);
  rpcc* find_or_make_rpcc(std::string buf);
  lock_protocol::status release(lock_protocol::lockid_t lid, int &);
};

#endif
